package com.java.common.lang.domain.page;

import javax.validation.constraints.Max;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Positive;

import com.java.common.utils.StringUtils;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

/**
 * 分页数据
 * 
 * @author Administrator
 */
@ApiModel(value = "分页请求")
public class PageDomain {

    /** 当前记录起始索引 */
    @ApiModelProperty(value = "查询页数", required = true, position = 1, notes = "1")
    @NotNull
    @Positive
    private Integer pageNum;

    /** 每页显示记录数 */
    @ApiModelProperty(value = "每页数量", required = true, position = 2, notes = "15")
    @Max(value = 50)
    @NotNull
    @Positive
    private Integer pageSize;

    /** 排序列 */
    @ApiModelProperty(value = "排序字段", required = false, position = 3)
    @Pattern(regexp = "^[a-z_]+$", message = "排序字段有误")
    private String orderByColumn;

    /** 排序的方向desc或者asc */
    @ApiModelProperty(value = "排序类型（asc或desc）", required = false, position = 4)
    @Pattern(regexp = "^asc$|^desc$", message = "排序类型有误")
    private String isAsc = "asc";

    @ApiModelProperty(hidden = true)
    public String getOrderBy() {
        if (StringUtils.isEmpty(orderByColumn)) {
            return "";
        }
        return StringUtils.toUnderScoreCase(orderByColumn) + " " + isAsc;
    }

    public Integer getPageNum() {
        return pageNum;
    }

    public void setPageNum(Integer pageNum) {
        this.pageNum = pageNum;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public String getOrderByColumn() {
        return orderByColumn;
    }

    public void setOrderByColumn(String orderByColumn) {
        this.orderByColumn = orderByColumn;
    }

    public String getIsAsc() {
        return isAsc;
    }

    public void setIsAsc(String isAsc) {
        this.isAsc = isAsc;
    }

}